package com.springboot.learn.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.stereotype.Component;

/**
 *describe: 
 *
 *@author zhanghaixuan
 *@date 2018/12/25
 **/
public class MacConditional implements Condition {
	/**
	 *
	 * @param context 判断条件能使用的上下文环境(环境)
	 * @param metadata 注释信息
	 * @return boolean
	 */
	public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
		//判断是否mac 系统
		//获取ben工厂
		context.getBeanFactory();
		//获取类加载器
		context.getClassLoader();
		//获取bean定义的注册类
		context.getRegistry();
		//获取环境变量
		Environment environment = context.getEnvironment();
		String property = environment.getProperty("os.name");
		if(property.equalsIgnoreCase("Mac OS X")){
			return true;
		}else{
			return false;
		}
	}
}
